/*
 * 		Author : Xerxes
 * 		Program: 
 * 		Created On : 29.09.2011 17:10:11 BDT
 *      "I have not failed, I have just found 10000 ways that won't work.
 * 
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int vt[20];
string line;
int sz;
inline void Read(){
		sz = LN(line);
		
		//cout<<sz<<" "<<line<<"\n";
		fo(i,0,sz){
			if( line[i]>='1' && line[i] <='9' ){
				vt[i] = line[i]-'1';
			}
			else if( line[i]>='A' && line[i]<='F' ){
				vt[i] = (line[i]-'A')  ;
				vt[i]+=9;
			}
			else{
				vt[i] = -1;
			}
		}
}


int r[] = {-1,+0,+1};
int c[] = {+1,+1,+1};
char cc[] = {'.','.','.'};
char g[20][20];
Int cando[ 20 ][ 20 ];

inline Int go(int col){
		if( col==sz ){
			return (Int)1;
		}
		
		
		Int res = (Int)0;
		if( vt[col] != -1 ){
				int row = vt[col];
				if(g[row][col]=='.'){
						
						fo(i,0,3){
							int tr = row+r[i];
							int tc = col+c[i];
							if( tr<0 || tc<0 || tr>=sz || tc>=sz)continue;
							
							cc[i] = g[tr][tc];
							g[tr][tc]='@';
							
						}
						Int &var = cando[row][col];
						if( var!=-1 ){
							res+= var;
						}
						else{
							var = go(col+1);
							res+=var;
						}
						fo(i,0,3){
							int tr = row+r[i];
							int tc = col+c[i];
							if( tr<0 || tc<0 || tr>=sz || tc>=sz)continue;
							g[tr][tc]= cc[i];
						}
						
				}
				
		}
		else{
			// try all possible row
			for(int row = 0; row<sz; ++row){
					if(g[row][col]=='.'){
						
						fo(i,0,3){
							int tr = row+r[i];
							int tc = col+c[i];
							if( tr<0 || tc<0 || tr>=sz || tc>=sz)continue;
							
							cc[i] = g[tr][tc];
							g[tr][tc]='@';
							
						}
						Int &var = cando[row][col];
						if( var!=-1 ){
							res+= var;
						}
						else{
							var = go(col+1);
							res+=var;
						}
						fo(i,0,3){
							int tr = row+r[i];
							int tc = col+c[i];
							if( tr<0 || tc<0 || tr>=sz || tc>=sz)continue;
							g[tr][tc]= cc[i];
						}
						
					}	
			}
		}
		
return res;
}

inline void Proc(){
		SET(cando,-1);
		fo(i,0,sz){
			fo(j,0,sz){
				g[i][j]='.';
			}
		}
		Int var = go(0);
		cout<<var<<"\n";
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
    #endif
    while( cin>>line ){
		Read();
		Proc();
	}
	
return 0;
}


